BEGIN  { Goal=1; All="_"; OFS=FS=","; Select=0; Support=20; Target=1 }
NR==1  { srand(Seed ? Seed : 1)
         Header=$0
         for(I=1;I<=NF;I++) 
	    readHeader(I,$I,Name,Index,\
                       Num,Sym,Dep,Indep)
	 for(I in Dep) Klass=I
         next
       }
NR > 1 && (rand() < Select) { 
    	H[$Klass]++;
	H[All]++; 
	for(I in Name) 
	    if(! (I in Ignore)) 
		if (I != Klass) {
		    Thing = I _ $I
		    if (++R[Thing]==1) U[I]++
		    F[$Klass _ Thing]++
		    F[All _ Thing]++ 
		}
	
}
END {
    fyi("contrast... ") 
    for(X in H) 
	if (X == Target)
	    contrast(X)
    fyi("sample : " H[All] " Select " Select)
}
function contrast(h,  b0,bs,b,r0,rs,r,score,com,max,scores,name,val,interesting,dull,best) {
    print "\n#============================\nclass " h
    com="sort   -k 2 -r  #" rand()
    max = -100000000000000   
    for(x in R) 
	if((h _ x) in F) {
	     split(x,tmp,_)
	     if (U[tmp[1]] < 2) continue
	     name=Name[tmp[1]];#print Name
	     if ((tmp[1] in Indep)) {
	     val=tmp[2]
	     b0 = F[h _ x]
	     if (b0 > Support) { #print name
		 bs = H[h]
		 b  = b0/(bs + 0.0001)
		 r0 = F[All _ x] - b0
		 rs = H[All]     - bs
		 r  = r0/(rs + 0.0001)
		 if (b>r) {
		     interesting[name]
		     #score= log(b/r)
		     score= b^2/(b+r)
		     info[name,val] =  "   " score OFS name"="val OFS "b0" OFS b0 \
			 OFS "bs" OPS bs OFS "b" OFS b OFS "r0" OFS r0	\
			 OFS "rs" OFS rs OFS "r" OFS r 
		     scores[name,val] = score
		     if(score > max) max=score
		     if (score > best[name]) best[name]=score
		 }}}}
    #for(x in best)
#	if (best[name] < 0.33*max)
#	    dull[name]
    for(x in scores) {
	split(x,tmp,SUBSEP)
	name=tmp[1]
	val=tmp[2]
	if (name in interesting && (best[name]> 0.5 * max))
	    printf("%10.9f %s %s\n", scores[x],name " " val, info[x]) | com }
    close(com)
}
	